const express = require("express");
const listService = require("../services/list");
const {List} = require("../models/list");

let router = express.Router();

router.get("/getBasicList", async (req, res, next) => {
    try {

        const {page, pageSize} = req.query;
        const result = await listService.getBasicTable(page, pageSize);
        const total = await List.count();
        const data = {data: result, total: total};
        res.send({code: 200, msg: "请求成功", data: data});

    } catch (e) {
        next(e);
    }
});

router.get("/getPageList", async (req, res, next) => {
    try {

        const {page, pageSize} = req.query;
        const result = await listService.getPageTable(page, pageSize);
        const total = await List.count();
        const data = {data: result, total: total};
        res.send({code: 200, msg: "请求成功", data: data});

    } catch (e) {
        next(e);
    }
});

router.get("/getComplexList", async (req, res, send) => {
    try {

        const {page, pageSize} = req.query;
        const result = await listService.getComplexTable(page, pageSize);
        const total = await List.count();
        const data = {data: result, total: total};
        res.send({code: 200, msg: "请求成功", data: data});
    } catch (e) {
        next(e);
    }
})

module.exports = router;
